package com.daodao.daodaoschedule.application.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daodao.daodaoschedule.domain.wechat.WechatMember;
import com.daodao.daodaoschedule.infrastructure.dao.entity.WechatMemberPO;
import com.daodao.daodaoschedule.infrastructure.dao.mapper.WechatMemberMapper;
import com.daodao.daodaoschedule.infrastructure.util.BeanCopyUtils;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mal
 * @date 2022-09-03 11:13
 */
@Slf4j
@Service
public class WechatMemberService extends ServiceImpl<WechatMemberMapper, WechatMemberPO> implements IWechatMemberService {



    public List<WechatMemberPO> getAllValidMember() {
        List<WechatMemberPO> wechatMemberPOS = baseMapper.selectList(new QueryWrapper<WechatMemberPO>().lambda().eq(WechatMemberPO::getState, "1"));
        return wechatMemberPOS;

    }

    public List<WechatMember> getByWrapper(LambdaQueryWrapper<WechatMemberPO> queryWrapper) {
        List<WechatMemberPO> wechatMemberPOS = baseMapper.selectList(
                queryWrapper);

        return BeanCopyUtils.mapAsList(wechatMemberPOS, WechatMember.class);

    }

    public List<WechatMember> getMemberList(Long accountId) {
        List<WechatMemberPO> wechatMembers = baseMapper.selectList(
                new LambdaQueryWrapper<WechatMemberPO>().eq(WechatMemberPO::getAccountId,accountId));
        return BeanCopyUtils.mapAsList(wechatMembers, WechatMember.class);


    }



    public int saveMember(WechatMemberPO wechatMemberPO) {
        return baseMapper.insert(wechatMemberPO);
    }

}
